package com.yh.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yh.common.BaseResult;
import com.yh.entity.SysUser;
import com.yh.service.ISysUserService;
import org.springframework.boot.context.properties.bind.DefaultValue;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import lombok.AllArgsConstructor;

import java.util.Map;

/**
 * <p>
 * 用户 用户登录信息表 前端控制器
 * </p>
 *
 * @author yh
 * @since 2021-04-06
 */
@AllArgsConstructor
@RestController
@RequestMapping("/sysUser")
public class SysUserController {
    private final ISysUserService sysUserService;

    @PostMapping
    public BaseResult createUser(@RequestBody SysUser sysUser){
        SysUser user = sysUserService.createUser(sysUser);
        return BaseResult.ok(user);
    }

    @PutMapping
    public BaseResult updateUser(@RequestBody SysUser sysUser){
        SysUser user = sysUserService.updateUser(sysUser);
        return BaseResult.ok(user);
    }

    @GetMapping
    @PreAuthorize("hasAuthority('/user')")
    public BaseResult getInfo(@RequestParam("id") Long id){
        SysUser user = sysUserService.getInfo(id);
        return BaseResult.ok(user);
    }

    @GetMapping("/getUserInfo")
    public BaseResult getInfo(@RequestParam("token") String token){
        Map<String,Object> map = sysUserService.getUserInfo(token);
        return BaseResult.ok(map);
    }

    @PostMapping("/getPage")
    public BaseResult getInfo(Integer pageNum,Integer pageSize){
        Page<SysUser> page = sysUserService.getPage(pageNum,pageSize);
        return BaseResult.ok(page);
    }

}

